#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int maxSatisfied(vector<int> &customers, vector<int> &grumpy, int X)
    {
        int tmp = 0, i = 0, j = 0, ans = -1;
        for (int t = 0; t < grumpy.size(); ++t)
            tmp += grumpy[t] == 0 ? customers[t] : 0;
        for (; j < grumpy.size() && j - i + 1 <= X; j++)
            tmp += grumpy[j] == 1 ? customers[j] : 0;
        ans = tmp, j--;
        for (; j + 1 < grumpy.size(); j++, i++)
        {
            tmp += grumpy[j + 1] == 1 ? customers[j + 1] : 0;
            tmp -= grumpy[i] == 1 ? customers[i] : 0;
            ans = max(ans, tmp);
        }
        return ans;
    }
};